import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import vueJsx from '@vitejs/plugin-vue-jsx'
import commonjs from '@rollup/plugin-commonjs'
import path from 'path'
import Unocss from 'unocss/vite'
import { pluginsConfig, resolve, NODE_ENV, injectProcessEnv } from './config'

// https://vitejs.dev/config/
export default defineConfig({
  // build: {
  //   rollupOptions: {
  //     external: ['axios/lib/core/createError'],
  //   },
  // },
  plugins: [
    ...pluginsConfig,
    vueJsx(),
    commonjs(),
    uni(),
    // https://github.com/antfu/unocss
    Unocss()
  ],
  server: {
    // port: 8080,
    host: '0.0.0.0',
    proxy: {
      '/api/': {
        target: 'https://api-sandbox.smart-key.cn/tenant-supplier',
        // target: 'http://192.168.40.30:8093',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/api/, '')
      }
      // '/api-prod/': {
      //   target: 'http://localhost:3001',
      //   changeOrigin: true,
      //   rewrite: (p) => p.replace(/^\/api-prod/, '')
      // }
    }
  },
  resolve: {
    extensions: ['.jsx', '.tsx', '.js', '.ts', '.json', '.vue'],
    alias: {
      // '@': path.resolve(__dirname, './src'),
      // '@components': path.resolve(__dirname, './src/components')
      '@': resolve('src'),
      '@components': resolve('src/components')
    }
  },
  css: {
    // 配置`scss`和`less`全局变量
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/styles/vars/_base.scss";'
      },
      less: {
        additionalData: '@import "@/styles/vars/_base.less";'
      }
    }
  }
})
